package com.mikasa.springboot.example.redismq;

import com.mikasa.springboot.example.redis.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by User on 17/1/12.
 */

@Service
public class UserMessageProvider implements Runnable{

    private static final Logger LOGGER = LoggerFactory.getLogger(UserMessageProvider.class);

    @Autowired
    private RedisUtil redisUtil;

    private ConcurrentHashMap<String,Object> map;

    public void setMap(ConcurrentHashMap<String, Object> map) {
        this.map = map;
    }

    @Override
    public void run() {
        String channel = map.get("channel").toString();
        String message = map.get("message").toString();
        LOGGER.info("channel:"+channel+"[message]"+message);
        //发布消息
        redisUtil.sendMessage(channel,message);
        LOGGER.info(channel+"发布消息:"+message);
    }
}
